import { resolve } from "path";
import { defineConfig, externalizeDepsPlugin } from "electron-vite";
import { NaiveUiResolver } from "unplugin-vue-components/resolvers";
import vue from "@vitejs/plugin-vue";
import AutoImport from "unplugin-auto-import/vite";
import Components from "unplugin-vue-components/vite";
import Icons from "unplugin-icons/vite";
import IconsResolver from "unplugin-icons/resolver";
import tailwindcss from "@tailwindcss/vite";

export default defineConfig({
  main: {
    plugins: [externalizeDepsPlugin()],
  },
  preload: {
    plugins: [externalizeDepsPlugin()],
  },
  renderer: {
    resolve: {
      alias: {
        "@renderer": resolve("src/renderer/src"),
      },
    },
    // vite插件
    plugins: [
      // vue支持
      vue(),
      // 引入tailwindcss
      tailwindcss(),
      // 自动引入图标组件
      Icons({
        compiler: "vue3",
        // 启用自动安装图标集
        autoInstall: true,
      }),
      // 自动导入
      AutoImport({
        imports: [
          "vue",
          {
            "naive-ui": ["useDialog", "useMessage", "useNotification", "useLoadingBar"],
          },
          "pinia",
          "vue-router",
        ],
      }),
      // 自动引入组件
      Components({
        resolvers: [
          // 自动引入 Naive UI 组件
          NaiveUiResolver(),
          // 自动引入图标组件
          IconsResolver({
            // 自动引入的组件前缀，默认为 i
            prefix: "i",
            // 引入的图标集
            enabledCollections: ["material-symbols", "solar", "ion", "line-md", "mdi", "tabler", "jam"],
          }),
        ],
      }),
    ],
    // 开发服务器配置
    server: {
      host: "127.0.0.1",
    },
  },
});
